<?
include("session.php");
$role_name = $_SESSION['role_name'];
$id = "";
if(isset($_GET['id'])) {
	$id = $_GET['id'];
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="../webkit/utils/jquery.js"></script>
<script type="text/javascript" src="../webkit/utils/form.checker.js"></script>
<script type="text/javascript" src="../webkit/datepicker/WdatePicker.js"></script>
<link type="text/css" rel="stylesheet" href="page.css"/> 
<body  bgcolor="#f4f4f4" style="margin:0px;" scroll=no onload="init()">

<form name=f> 
<hr size=1>
<table width=100% cellspacing=1 cellpadding=3 id="basic_info_table"> 
	<tr>
        <td align=right nowrap>登录账号</td><td><input type='text' id="user_name" class='input' check='not_empty' warning='登录账号不能为空！'></td>  
		<td align=right>账号状态</td><td><select id="user_status" class='input'><option value=0>有效</option><option value=-1>无效</option></select></td>
	</tr>
	<tr>
		<td align=right>登录密码</td><td><input type='password' id="user_pass" class='input' check='not_empty' warning='登录密码不能为空！'></td>
		<td align=right>确认密码</td><td><input type='password' id="r_user_pass" class='input' check='not_empty' warning='确认密码不能为空！'></td>
	</tr>
	<tr>
		<td align=right>用户名称</td><td><input type='text' id="true_name" class='input' check='not_empty' warning='用户名称不能为空！'></td>
		<td align=right>联系电话</td><td><input type='text' id="contact_tel" class='input' check='not_empty' warning='联系电话不能为空！'></td>
	</tr>
	<tr>
		<td align=right>用户角色</td><td><select id="user_flag" class='input'><option value='user'>普通用户</option><option value='admin'>管理员</option></select></td>
		<td align=right>&nbsp;</td><td>&nbsp;</td>
	</tr>
	<tr>
		<td align=right>外呼号码</td><td><input type='text' id="callout_number" class='input' check='not_empty' warning='外呼号码不能为空！'></td>
		<td align=right>可呼条数</td><td><input type='text' id="callable_count" class='input' check='not_empty' warning='可呼条数不能为空！'></td>
	</tr>
	<tr>
		<td align=right>备　　注</td><td colspan=3><textarea style="width:500px;" rows=4 id="user_desc"></textarea></td>
	</tr>
	<input type='hidden' id="id">
</form>	

<table width=100% cellspacing=1 cellpadding=3>
	<tr>
		<td align=center>
		<hr size=1>
		<input type="button" id="btn_save" class="button" value="保存信息" onclick="save()">　　<input type="button" class="button" value="关闭窗口" onclick="parent.closeDlg()"></td>
	</tr>
</table>

<script type="text/javascript">
	var op = "<?echo $_GET['op']?>";
	var f = document.f;
	function save() { 
		if(FormChecker.doCheck(f)) {
			if($('#user_pass').val() != $('#r_user_pass').val()) {
				alert("密码确认不一致，请检查！");
				return false;
			}
			var params = {};
			var els = f.elements;
			for(var i=0; i<els.length; i++) {
				if(els[i].type == "button" || els[i].id == "r_user_pass") continue;
				params[els[i].id] = els[i].value;
			}

			$.post("user_query.php?action="+op, params, function(data) {
				if(data.indexOf("ok") == 0) {
					alert("数据保存成功!");
					parent.refreshGrid();
					parent.closeDlg();
                } else if(data == 'username_exists') {
					alert('用户名已经存在，请另选！')
				} else {  
					alert(data);
				}
			});
		}
	}; 

	

	function init() {
	<?
	if($_GET['op'] == 'edit') {
	?>
	$.get("user_query.php?action=get&id=<?echo $_GET['id']?>", function(data){
		eval("var row = "+data);
		for(var k in row) {
			$('#'+k).val(row[k]);
		}
		$('#r_user_pass').val(row['user_pass'])
	});
	<?
	}
	?>
	}


</script>
</body>
</html>